package com.woniuxy.intellihome.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.woniuxy.intellihome.entity.Spec;
import com.woniuxy.intellihome.entity.SpecDetail;
import com.woniuxy.intellihome.mapper.SpecMapper;
import com.woniuxy.intellihome.service.SpecDetailService;
import com.woniuxy.intellihome.service.SpecService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author jobob
 * @since 2021-08-11
 */
@Service
public class SpecServiceImpl extends ServiceImpl<SpecMapper, Spec> implements SpecService {
    @Autowired
    private SpecService specService;
    @Autowired
    private SpecDetailService detailService;

    @Override
    public List<Spec> getByGoodsId(int id) {
        Spec spec1=new Spec();
        spec1.setGoodsId(id);
        Wrapper<Spec> wrapper=new QueryWrapper<>(spec1);
        List<Spec> specs = specService.list(wrapper);
        for (Spec spec : specs) {
            List<SpecDetail> detailList = detailService.getBySpecId(spec.getId());
            spec.setSpecDetails(detailList);
        }
        return specs;
    }

    /**
     * 得到规格spec (内赋值details 的list)
     * @param id spec的id
     * @return
     */
    @Override
    public Spec getDetailedById(int id) {
        Spec spec = specService.getById(id);
        spec.setSpecDetails(detailService.getBySpecId(id));
        return spec;
    }

    @Override
    public List<Integer> getspecIdsByGoodsId(int goods_id) {
        return specService.getspecIdsByGoodsId(goods_id);
    }
}
